package boot;
import java.util.Timer;
import java.util.TimerTask;

import javax.microedition.media.MediaException;

public class RestartManager {

	private Boot boot;
	Timer timer;

	public RestartManager(Boot aBoot) {
		boot = aBoot;
	}

	public void restartPlayer(long playerTime) {

		timer = new Timer();
		timer.schedule(new RestartTask(playerTime), 1000, 1000);
	}
	
	private class RestartTask extends TimerTask {
		
		long time;

		public RestartTask(long aTime) {
			time = aTime;
		}
		
		public void run() {
			boolean restarted = true;
			try {
				boot.restart(time);
			} catch (MediaException e) {
				restarted = false;
			}
			if (restarted) {
				timer.cancel();
			}
		}
	}
}
